﻿var Profile = function () {
    var initCommon = function () {
        var sidebarMenu = $("#sidebarMenu");
        var profileContent = $("#profile_content");

        sidebarMenu
        .delegate("li > a", "click", function () {
            var link = $(this);
            var parent = link.parent();

            parent.addClass("active");
            parent.siblings().removeClass("active");

            var loading = '<div class="row">' + 
                          '  <div class="col-md-12">' + 
                          '    <div class="portlet light">' +      
                          '        <div class="portlet-body">' + 
                          '           <img src="/assets/global/img/loading-spinner-grey.gif" alt="" class="loading">' + 
                          '           <span>&nbsp;&nbsp;页面载入中…… </span>' + 
                          '        </div>' + 
                          '    </div>' +
                          '  </div>' + 
                          '</div>'
            profileContent.empty().append(loading);
            profileContent.load(this.href, { ajax: true }, function (a, b, c) {
                switch (c.status) {
                    case 203:
                        profileContent.empty().load("/Error/C203");
                        break;
                    case 500:
                        profileContent.empty().load("/Error/C500");
                        break;
                }
            });

            return false;
        })
        .find("li:eq(0) > a").trigger("click");
    };

    return {
        init: function () {
            initCommon();
        }
    };
} ();